#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <algorithm>
#include <utility>
#include <initializer_list>

#include "SteelClientAPI.h"

using DataPoint = std::pair<double, double>;

void fillSeries(MainPageChartSeriesData& series, const std::initializer_list<std::pair<double, double>>& points)
{
    series.count = 0;
    for (const auto& point : points) {
        if (series.count >= MAIN_PAGE_CHART_MAX_POINTS) {
            break;
        }
        series.points[series.count].x = point.first;
        series.points[series.count].y = point.second;
        ++series.count;
    }
}

MainPageChartTableData makeChartTableData(const std::initializer_list<std::initializer_list<const char*>>& rows)
{
    MainPageChartTableData table{};
    int rowIndex = 0;
    for (const auto& row : rows) {
        if (rowIndex >= MAIN_PAGE_CHART_TABLE_ROWS) {
            break;
        }
        int columnIndex = 0;
        for (const char* text : row) {
            if (columnIndex >= MAIN_PAGE_CHART_TABLE_COLUMNS) {
                break;
            }
            if (text) {
                std::strncpy(table.items[rowIndex][columnIndex], text,
                             sizeof(table.items[rowIndex][columnIndex]) - 1);
                table.items[rowIndex][columnIndex][sizeof(table.items[rowIndex][columnIndex]) - 1] = '\0';
            }
            ++columnIndex;
        }
        ++rowIndex;
    }
    return table;
}

MainPageChartData makeChartData(double lanceOffset, double flowOffset, const DataPoint& limePoint,
                                const DataPoint& rawWhitePoint, const DataPoint& ironOrePoint)
{
    MainPageChartData data{};

    fillSeries(data.actualLanceSeries, {
        {0.0, 2000.0 - lanceOffset}, {1.0, 1800.0 - lanceOffset}, {2.0, 1500.0 - lanceOffset},
        {3.0, 1300.0 - lanceOffset}, {4.0, 1150.0 - lanceOffset}, {5.0, 1100.0 - lanceOffset}
    });

    fillSeries(data.standardLanceSeries, {
        {0.0, 1900.0 - lanceOffset}, {1.0, 1700.0 - lanceOffset}, {2.0, 1500.0 - lanceOffset},
        {3.0, 1350.0 - lanceOffset}, {4.0, 1200.0 - lanceOffset}, {5.0, 1100.0 - lanceOffset}
    });

    fillSeries(data.oxygenFlowSeries, {
        {0.0, 1500.0 + flowOffset}, {1.0, 1700.0 + flowOffset}, {2.0, 2100.0 + flowOffset},
        {3.0, 2200.0 + flowOffset}, {4.0, 2000.0 + flowOffset}, {5.0, 1900.0 + flowOffset}
    });

    fillSeries(data.limeClassSeries, {limePoint});
    fillSeries(data.rawWhiteClassSeries, {rawWhitePoint});
    fillSeries(data.ironOreClassSeries, {ironOrePoint});

    return data;
}

MainPageOperStageData makeOperStageData(const std::initializer_list<std::initializer_list<const char*>>& rows)
{
    MainPageOperStageData data{};
    int rowIndex = 0;
    for (const auto& row : rows) {
        if (rowIndex >= MAIN_PAGE_OPER_STAGE_ROWS) {
            break;
        }
        int columnIndex = 0;
        for (const char* text : row) {
            if (columnIndex >= MAIN_PAGE_OPER_STAGE_COLUMNS) {
                break;
            }
            if (text) {
                std::strncpy(data.stageItems[rowIndex][columnIndex], text,
                             sizeof(data.stageItems[rowIndex][columnIndex]) - 1);
                data.stageItems[rowIndex][columnIndex][sizeof(data.stageItems[rowIndex][columnIndex]) - 1] = '\0';
            }
            ++columnIndex;
        }
        ++rowIndex;
    }
    return data;
}

MainPageOperTotalData makeOperTotalData(const std::initializer_list<std::initializer_list<const char*>>& rows)
{
    MainPageOperTotalData data{};
    int rowIndex = 0;
    for (const auto& row : rows) {
        if (rowIndex >= MAIN_PAGE_OPER_TOTAL_ROWS) {
            break;
        }
        int columnIndex = 0;
        for (const char* text : row) {
            if (columnIndex >= MAIN_PAGE_OPER_TOTAL_COLUMNS) {
                break;
            }
            if (text) {
                std::strncpy(data.totalItems[rowIndex][columnIndex], text,
                             sizeof(data.totalItems[rowIndex][columnIndex]) - 1);
                data.totalItems[rowIndex][columnIndex][sizeof(data.totalItems[rowIndex][columnIndex]) - 1] = '\0';
            }
            ++columnIndex;
        }
        ++rowIndex;
    }
    return data;
}

MainPageProcessData makeProcessData(int currentStage, const char* currentTime, const std::initializer_list<bool>& completed)
{
    MainPageProcessData data{};
    data.currentStage = std::clamp(currentStage, 0, MAIN_PAGE_PROCESS_STAGE_COUNT - 1);
    if (currentTime) {
        std::strncpy(data.currentTime, currentTime, sizeof(data.currentTime) - 1);
        data.currentTime[sizeof(data.currentTime) - 1] = '\0';
    }
    int idx = 0;
    for (bool value : completed) {
        if (idx >= MAIN_PAGE_PROCESS_STAGE_COUNT) {
            break;
        }
        data.stageCompleted[idx++] = value;
    }
    return data;
}

// Working condition data change callback function
void onWorkingConditionChanged(NavTreeIndex index, const ConfigWorkingConditionData* data, void* userData)
{
    (void)userData; // Unused parameter
    
    std::cout << "\n[Callback] Working Condition Data Changed - Index: " << static_cast<int>(index) << std::endl;
    std::cout << "  Molten Iron Composition: Mn=" << data->moltenIron.Mn 
              << ", P=" << data->moltenIron.P 
              << ", S=" << data->moltenIron.S 
              << ", Ti=" << data->moltenIron.Ti << std::endl;
    std::cout << "  Target Composition: C=" << data->target.C 
              << ", Si=" << data->target.Si 
              << ", Mn=" << data->target.Mn 
              << ", T=" << data->target.T << "°C" << std::endl;
    std::cout << "  Scrap Steel Composition: C=" << data->scrapSteel.C 
              << ", Si=" << data->scrapSteel.Si 
              << ", Mn=" << data->scrapSteel.Mn << std::endl;
    std::cout << "  Chute Flow: Normal=" << data->chuteFlow.normal 
              << ", Retain=" << data->chuteFlow.retain 
              << ", More=" << data->chuteFlow.more << std::endl;
}

// Oxygen lance data change callback function
void onOxygenLanceChanged(NavTreeIndex index, const ConfigOxygenLanceData* data, void* userData)
{
    (void)userData; // Unused parameter
    
    std::cout << "\n[Callback] Oxygen Lance Data Changed - Index: " << static_cast<int>(index) << std::endl;
    std::cout << "  Actual Oxygen Flow: " << data->actualOxygenFlow << " m³/min" << std::endl;
    std::cout << "  Post Blow Oxygen Utilization: " << data->postBlowOxygenUtilization << "%" << std::endl;
    std::cout << "  Initial Oxygen Factor: A=" << data->initialOxygenFactor.A 
              << ", B=" << data->initialOxygenFactor.B << std::endl;
    std::cout << "  Sintered Ore Grade: " << data->sinteredOreGrade << "%" << std::endl;
    std::cout << "  Oxygen Supply - Sinter: " << data->oxygenSupply.sinter 
              << ", Steel: " << data->oxygenSupply.steel 
              << ", Coke: " << data->oxygenSupply.coke << std::endl;
    std::cout << "  Lance Division: [";
    for (int i = 0; i < 6; ++i) {
        std::cout << data->lanceDivision[i];
        if (i < 5) std::cout << ", ";
    }
    std::cout << "]" << std::endl;
}

// Material data change callback function
void onMaterialChanged(NavTreeIndex index, const ConfigMaterialData* data, void* userData)
{
    (void)userData; // Unused parameter
    
    std::cout << "\n[Callback] Material Data Changed - Index: " << static_cast<int>(index) << std::endl;
    std::cout << "  Feeding Mode: " << data->feedingMode.mode << std::endl;
    std::cout << "  Feeding Parameters: CSJK=" << data->feedingMode.csjk 
              << ", GSJK=" << data->feedingMode.gsjk << std::endl;
}

// Login validation callback function
bool onLoginValidation(const char* username, const char* password, char* errorMessage, int errorMessageSize, void* userData)
{
    (void)userData; // Unused parameter
    
    std::cout << "\n[Callback] Login Validation - Username: " << username << std::endl;
    
    // Example validation logic
    // You can replace this with your own validation logic (database, API call, etc.)
    
    // Simple validation example: accept "admin"/"admin123" or "user"/"user123"
    if (std::strcmp(username, "admin") == 0 && std::strcmp(password, "admin123") == 0) {
        std::cout << "  [OK] Login successful for admin" << std::endl;
        return true;
    }
    
    if (std::strcmp(username, "user") == 0 && std::strcmp(password, "user123") == 0) {
        std::cout << "  [OK] Login successful for user" << std::endl;
        return true;
    }
    
    // Login failed - set error message
    if (errorMessage && errorMessageSize > 0) {
        std::string errorMsg = "Invalid username or password";
        std::strncpy(errorMessage, errorMsg.c_str(), errorMessageSize - 1);
        errorMessage[errorMessageSize - 1] = '\0';
    }
    
    std::cout << "  [FAIL] Login failed - Invalid username or password" << std::endl;
    return false;
}

// Main page working condition data callback
void onMainPageWorkingConditionChanged(NavTreeIndex index, const MainPageWorkingConditionData* data, void* userData)
{
    (void)userData;
    std::cout << "\n[Callback] MainPage Working Condition Data Changed - Index: " << static_cast<int>(index) << std::endl;
    std::cout << "  Item Count: " << data->count << std::endl;
    for (int i = 0; i < data->count; ++i) {
        std::cout << "    - " << data->items[i].name << " = " << data->items[i].value << std::endl;
    }
}

// Main page material data callback
void onMainPageMaterialChanged(NavTreeIndex index, const MainPageMaterialData* data, void* userData)
{
    (void)userData;
    std::cout << "\n[Callback] MainPage Material Data Changed - Index: " << static_cast<int>(index) << std::endl;
    std::cout << "  Item Count: " << data->count << std::endl;
    for (int i = 0; i < data->count; ++i) {
        std::cout << "    - " << data->items[i].name << " = " << data->items[i].value << std::endl;
    }
}

// Main page oxygen lance data callback
void onMainPageOxygenLanceChanged(NavTreeIndex index, const MainPageOxygenLanceData* data, void* userData)
{
    (void)userData;
    std::cout << "\n[Callback] MainPage Oxygen Lance Data Changed - Index: " << static_cast<int>(index) << std::endl;
    std::cout << std::fixed << std::setprecision(2)
              << "  Oxygen Flow: " << data->oxygenFlow
              << ", Lance Height: " << data->lanceHeight
              << ", Reading Blow: " << data->readingBlowQuantity
              << ", Accumulated Blow: " << data->accumulatedBlowQuantity
              << ", Converter Angle: " << data->converterAngle
              << ", Oxygen Pressure: " << data->oxygenPressure
              << std::endl;
}

// Main page blowing data callback
void onMainPageBlowingChanged(NavTreeIndex index, const MainPageBlowingData* data, void* userData)
{
    (void)userData;
    std::cout << "\n[Callback] MainPage Blowing Data Changed - Index: " << static_cast<int>(index) << std::endl;
    std::cout << "  Current Time: " << data->currentBlowingTime
              << ", Remaining Time: " << data->estimatedRemainingTime
              << ", Temperature: " << data->currentTemperature
              << ", Carbon Content: " << data->currentCarbonContent
              << ", Operating Mode: " << data->operatingMode
              << std::endl;
}

// Main page chart data callback
void onMainPageChartChanged(NavTreeIndex index, const MainPageChartData* data, void* userData)
{
    (void)userData;
    auto printSeries = [](const char* name, const MainPageChartSeriesData& series) {
        std::cout << "    " << name << " (" << series.count << " points): ";
        int limit = std::min(series.count, 5);
        for (int i = 0; i < limit; ++i) {
            std::cout << "(" << series.points[i].x << ", " << series.points[i].y << ")";
            if (i < limit - 1) {
                std::cout << ", ";
            }
        }
        if (series.count > limit) {
            std::cout << ", ...";
        }
        std::cout << std::endl;
    };

    std::cout << "\n[Callback] MainPage Chart Data Changed - Index: " << static_cast<int>(index) << std::endl;
    printSeries("Actual Lance", data->actualLanceSeries);
    printSeries("Standard Lance", data->standardLanceSeries);
    printSeries("Oxygen Flow", data->oxygenFlowSeries);
    printSeries("Lime Class", data->limeClassSeries);
    printSeries("Raw White Class", data->rawWhiteClassSeries);
    printSeries("Iron Ore Class", data->ironOreClassSeries);
}

// Main page oper stage data callback
void onMainPageOperStageChanged(NavTreeIndex index, const MainPageOperStageData* data, void* userData)
{
    (void)userData;
    std::cout << "\n[Callback] MainPage Oper Stage Data Changed - Index: " << static_cast<int>(index) << std::endl;
    for (int row = 0; row < MAIN_PAGE_OPER_STAGE_ROWS; ++row) {
        std::cout << "    Row " << row << ": ";
        bool first = true;
        for (int col = 0; col < MAIN_PAGE_OPER_STAGE_COLUMNS; ++col) {
            const char* text = data->stageItems[row][col];
            if (text && text[0] != '\0') {
                if (!first) {
                    std::cout << " | ";
                }
                std::cout << text;
                first = false;
            }
        }
        std::cout << std::endl;
    }
}

// Main page oper total data callback
void onMainPageOperTotalChanged(NavTreeIndex index, const MainPageOperTotalData* data, void* userData)
{
    (void)userData;
    std::cout << "\n[Callback] MainPage Oper Total Data Changed - Index: " << static_cast<int>(index) << std::endl;
    for (int row = 0; row < MAIN_PAGE_OPER_TOTAL_ROWS; ++row) {
        std::cout << "    Row " << row << ": ";
        bool first = true;
        for (int col = 0; col < MAIN_PAGE_OPER_TOTAL_COLUMNS; ++col) {
            const char* text = data->totalItems[row][col];
            if (text && text[0] != '\0') {
                if (!first) {
                    std::cout << " | ";
                }
                std::cout << text;
                first = false;
            }
        }
        std::cout << std::endl;
    }
}

// Main page process data callback
void onMainPageProcessChanged(NavTreeIndex index, const MainPageProcessData* data, void* userData)
{
    (void)userData;
    std::cout << "\n[Callback] MainPage Process Data Changed - Index: " << static_cast<int>(index) << std::endl;
    std::cout << "  Current Stage: " << data->currentStage << ", Current Time: " << data->currentTime << std::endl;
    std::cout << "  Stage Completed: ";
    for (int i = 0; i < MAIN_PAGE_PROCESS_STAGE_COUNT; ++i) {
        std::cout << (data->stageCompleted[i] ? "1" : "0");
        if (i < MAIN_PAGE_PROCESS_STAGE_COUNT - 1) {
            std::cout << ",";
        }
    }
    std::cout << std::endl;
}

// Main page video data callback
void onMainPageVideoChanged(NavTreeIndex index, const MainPageVideoData* data, void* userData)
{
    (void)userData;
    std::cout << "\n[Callback] MainPage Video Data Changed - Index: " << static_cast<int>(index) << std::endl;
    std::cout << "  Status: " << data->status << ", Suggestion: " << data->suggestion
              << ", Abnormal: " << (data->abnormal ? "true" : "false") << std::endl;
}

// Main page video window handle callback
void onMainPageVideoWindowHandle(NavTreeIndex index, SteelClientWindowHandle handle, void* userData)
{
    (void)userData;
    auto flags = std::cout.flags();
    std::cout << "\n[Callback] MainPage Video Window Handle - Index: " << static_cast<int>(index) << std::endl;
    if (handle != 0) {
        std::cout << "  Handle: 0x" << std::hex << std::uppercase << handle << std::dec << std::nouppercase << std::endl;
    } else {
        std::cout << "  Handle not available yet (0)" << std::endl;
    }
    std::cout.flags(flags);
}

// Application shutdown callback
void onApplicationShutdown(void* userData)
{
    (void)userData;
    std::cout << "\n[Callback] Application shutdown confirmed by user. Cleaning up resources..." << std::endl;
}

// DebugWidget button click callback
void onDebugButtonClicked(int buttonType, bool isPressed, void* userData)
{
    (void)userData;
    const char* buttonNames[] = {
        "后吹",
        "B枪",
        "返干—轻微",
        "返干—重度",
        "顶喷",
        "双渣"
    };
    
    const char* buttonName = "未知";
    if (buttonType >= 0 && buttonType < 6) {
        buttonName = buttonNames[buttonType];
    }
    
    std::cout << "\n[Callback] DebugWidget Button Clicked" << std::endl;
    std::cout << "  Button: " << buttonName << " (Type: " << buttonType << ")" << std::endl;
    std::cout << "  State: " << (isPressed ? "Pressed" : "Released") << std::endl;
}

int main()
{
    std::cout << "=== Steel Client DLL Example Program ===" << std::endl;
    
    // Register callback functions
    std::cout << "\nRegistering callback functions..." << std::endl;
    
    int workingConditionCallbackId = registerWorkingConditionCallback(onWorkingConditionChanged, nullptr);
    if (workingConditionCallbackId > 0) {
        std::cout << "  [OK] Working Condition callback registered successfully, ID: " << workingConditionCallbackId << std::endl;
    } else {
        std::cerr << "  [FAIL] Failed to register Working Condition callback" << std::endl;
    }
    
    int oxygenLanceCallbackId = registerOxygenLanceCallback(onOxygenLanceChanged, nullptr);
    if (oxygenLanceCallbackId > 0) {
        std::cout << "  [OK] Oxygen Lance callback registered successfully, ID: " << oxygenLanceCallbackId << std::endl;
    } else {
        std::cerr << "  [FAIL] Failed to register Oxygen Lance callback" << std::endl;
    }
    
    int materialCallbackId = registerMaterialCallback(onMaterialChanged, nullptr);
    if (materialCallbackId > 0) {
        std::cout << "  [OK] Material callback registered successfully, ID: " << materialCallbackId << std::endl;
    } else {
        std::cerr << "  [FAIL] Failed to register Material callback" << std::endl;
    }
    
    int loginCallbackId = registerLoginCallback(onLoginValidation, nullptr);
    if (loginCallbackId > 0) {
        std::cout << "  [OK] Login callback registered successfully, ID: " << loginCallbackId << std::endl;
        std::cout << "       Valid credentials: admin/admin123 or user/user123" << std::endl;
    } else {
        std::cerr << "  [FAIL] Failed to register Login callback" << std::endl;
    }

    int mainPageWorkingCallbackId = registerMainPageWorkingConditionCallback(onMainPageWorkingConditionChanged, nullptr);
    if (mainPageWorkingCallbackId > 0) {
        std::cout << "  [OK] MainPage Working Condition callback registered successfully, ID: " << mainPageWorkingCallbackId << std::endl;
    } else {
        std::cerr << "  [FAIL] Failed to register MainPage Working Condition callback" << std::endl;
    }

    int mainPageMaterialCallbackId = registerMainPageMaterialCallback(onMainPageMaterialChanged, nullptr);
    if (mainPageMaterialCallbackId > 0) {
        std::cout << "  [OK] MainPage Material callback registered successfully, ID: " << mainPageMaterialCallbackId << std::endl;
    } else {
        std::cerr << "  [FAIL] Failed to register MainPage Material callback" << std::endl;
    }

    int mainPageOxygenCallbackId = registerMainPageOxygenLanceCallback(onMainPageOxygenLanceChanged, nullptr);
    if (mainPageOxygenCallbackId > 0) {
        std::cout << "  [OK] MainPage Oxygen Lance callback registered successfully, ID: " << mainPageOxygenCallbackId << std::endl;
    } else {
        std::cerr << "  [FAIL] Failed to register MainPage Oxygen Lance callback" << std::endl;
    }

    int mainPageBlowingCallbackId = registerMainPageBlowingCallback(onMainPageBlowingChanged, nullptr);
    if (mainPageBlowingCallbackId > 0) {
        std::cout << "  [OK] MainPage Blowing callback registered successfully, ID: " << mainPageBlowingCallbackId << std::endl;
    } else {
        std::cerr << "  [FAIL] Failed to register MainPage Blowing callback" << std::endl;
    }

    int mainPageChartCallbackId = registerMainPageChartCallback(onMainPageChartChanged, nullptr);
    if (mainPageChartCallbackId > 0) {
        std::cout << "  [OK] MainPage Chart callback registered successfully, ID: " << mainPageChartCallbackId << std::endl;
    } else {
        std::cerr << "  [FAIL] Failed to register MainPage Chart callback" << std::endl;
    }

    int mainPageOperStageCallbackId = registerMainPageOperStageCallback(onMainPageOperStageChanged, nullptr);
    if (mainPageOperStageCallbackId > 0) {
        std::cout << "  [OK] MainPage OperStage callback registered successfully, ID: " << mainPageOperStageCallbackId << std::endl;
    } else {
        std::cerr << "  [FAIL] Failed to register MainPage OperStage callback" << std::endl;
    }

    int mainPageOperTotalCallbackId = registerMainPageOperTotalCallback(onMainPageOperTotalChanged, nullptr);
    if (mainPageOperTotalCallbackId > 0) {
        std::cout << "  [OK] MainPage OperTotal callback registered successfully, ID: " << mainPageOperTotalCallbackId << std::endl;
    } else {
        std::cerr << "  [FAIL] Failed to register MainPage OperTotal callback" << std::endl;
    }

    int mainPageProcessCallbackId = registerMainPageProcessCallback(onMainPageProcessChanged, nullptr);
    if (mainPageProcessCallbackId > 0) {
        std::cout << "  [OK] MainPage Process callback registered successfully, ID: " << mainPageProcessCallbackId << std::endl;
    } else {
        std::cerr << "  [FAIL] Failed to register MainPage Process callback" << std::endl;
    }

    int mainPageVideoCallbackId = registerMainPageVideoCallback(onMainPageVideoChanged, nullptr);
    if (mainPageVideoCallbackId > 0) {
        std::cout << "  [OK] MainPage Video callback registered successfully, ID: " << mainPageVideoCallbackId << std::endl;
    } else {
        std::cerr << "  [FAIL] Failed to register MainPage Video callback" << std::endl;
    }

    int mainPageVideoWindowHandleCallbackId = registerMainPageVideoWindowHandleCallback(onMainPageVideoWindowHandle, nullptr);
    if (mainPageVideoWindowHandleCallbackId > 0) {
        std::cout << "  [OK] MainPage Video window handle callback registered successfully, ID: "
                  << mainPageVideoWindowHandleCallbackId << std::endl;
    } else {
        std::cerr << "  [FAIL] Failed to register MainPage Video window handle callback" << std::endl;
    }

    int shutdownCallbackId = registerApplicationShutdownCallback(onApplicationShutdown, nullptr);
    if (shutdownCallbackId > 0) {
        std::cout << "  [OK] Application shutdown callback registered successfully, ID: "
                  << shutdownCallbackId << std::endl;
    } else {
        std::cerr << "  [FAIL] Failed to register Application shutdown callback" << std::endl;
    }

    int debugButtonCallbackId = registerDebugButtonCallback(onDebugButtonClicked, nullptr);
    if (debugButtonCallbackId > 0) {
        std::cout << "  [OK] DebugWidget button callback registered successfully, ID: "
                  << debugButtonCallbackId << std::endl;
    } else {
        std::cerr << "  [FAIL] Failed to register DebugWidget button callback" << std::endl;
    }
    
    std::cout << "\nNote: When data is modified in the UI, the corresponding callback functions will be triggered" << std::endl;
    std::cout << "      When debug buttons are clicked, the debug button callback will be triggered" << std::endl;
    std::cout << "      The callback functions will output data change information to the console" << std::endl;
    std::cout << "      When logging in, the login callback will validate the credentials" << std::endl;
    
    const char* arg0 = "SteelClientExample";
    char* argv[] = {const_cast<char*>(arg0)};
    int argc = 1;

    setMainPageChartData(NavTreeIndex::Main_1, makeChartData(
        0.0, 0.0, DataPoint{1.2, 1400.0}, DataPoint{1.5, 1300.0}, DataPoint{3.0, 900.0}));
    setMainPageChartTableData(NavTreeIndex::Main_1, makeChartTableData({
        {"1200", "1250", "1300", "1350", "1400", "1450", "1500"},
        {"1150", "1180", "1210", "1240", "1270", "1300", "1330"}
    }));
    setMainPageChartData(NavTreeIndex::Main_2, makeChartData(
        50.0, 30.0, DataPoint{1.4, 1380.0}, DataPoint{1.7, 1250.0}, DataPoint{3.2, 920.0}));
    setMainPageChartTableData(NavTreeIndex::Main_2, makeChartTableData({
        {"1100", "1160", "1210", "1280", "1320", "1370", "1420"},
        {"1080", "1140", "1190", "1230", "1290", "1340", "1390"}
    }));
    setMainPageChartData(NavTreeIndex::Main_3, makeChartData(
        -40.0, 60.0, DataPoint{1.1, 1420.0}, DataPoint{1.6, 1280.0}, DataPoint{2.8, 940.0}));
    setMainPageChartTableData(NavTreeIndex::Main_3, makeChartTableData({
        {"1180", "1210", "1260", "1310", "1340", "1380", "1425"},
        {"1120", "1155", "1185", "1225", "1265", "1305", "1345"}
    }));
    setMainPageChartData(NavTreeIndex::Main_4, makeChartData(
        80.0, -20.0, DataPoint{1.3, 1365.0}, DataPoint{1.8, 1275.0}, DataPoint{3.4, 915.0}));
    setMainPageChartTableData(NavTreeIndex::Main_4, makeChartTableData({
        {"1250", "1290", "1330", "1370", "1410", "1450", "1490"},
        {"1205", "1235", "1265", "1295", "1325", "1355", "1385"}
    }));
    setMainPageChartData(NavTreeIndex::Main_5, makeChartData(
        -60.0, 90.0, DataPoint{1.25, 1410.0}, DataPoint{1.55, 1290.0}, DataPoint{3.1, 935.0}));
    setMainPageChartTableData(NavTreeIndex::Main_5, makeChartTableData({
        {"1195", "1230", "1275", "1315", "1350", "1385", "1420"},
        {"1140", "1170", "1205", "1240", "1270", "1305", "1340"}
    }));
    setMainPageChartData(NavTreeIndex::Main_6, makeChartData(
        30.0, -45.0, DataPoint{1.35, 1395.0}, DataPoint{1.65, 1265.0}, DataPoint{3.3, 905.0}));
    setMainPageChartTableData(NavTreeIndex::Main_6, makeChartTableData({
        {"1210", "1250", "1285", "1325", "1365", "1400", "1440"},
        {"1165", "1195", "1230", "1260", "1295", "1330", "1360"}
    }));

    setMainPageOperStageData(NavTreeIndex::Main_1, makeOperStageData({
        {"石灰 5.0t", "石灰石 3.0t", "高镁灰 2.0t", "烧结矿 6.0t", "萤石 0.5t", "废钢 4.0t", "合金 0.6t"},
        {"已投 2.5t", "已投 1.5t", "已投 1.0t", "已投 3.0t", "已投 0.2t", "已投 1.5t", "已投 0.3t"},
        {"剩余 2.5t", "剩余 1.5t", "剩余 1.0t", "剩余 3.0t", "剩余 0.3t", "剩余 2.5t", "剩余 0.3t"}
    }));
    setMainPageOperStageData(NavTreeIndex::Main_2, makeOperStageData({
        {"石灰 4.5t", "石灰石 2.8t", "高镁灰 2.2t", "烧结矿 5.5t", "萤石 0.6t", "废钢 4.2t", "合金 0.5t"},
        {"已投 2.0t", "已投 1.3t", "已投 1.2t", "已投 3.1t", "已投 0.3t", "已投 1.6t", "已投 0.2t"},
        {"剩余 2.5t", "剩余 1.5t", "剩余 1.0t", "剩余 2.4t", "剩余 0.3t", "剩余 2.6t", "剩余 0.3t"}
    }));
    setMainPageOperStageData(NavTreeIndex::Main_3, makeOperStageData({
        {"石灰 5.2t", "石灰石 3.5t", "高镁灰 2.0t", "烧结矿 6.5t", "萤石 0.7t", "废钢 4.5t", "合金 0.7t"},
        {"已投 3.0t", "已投 2.0t", "已投 1.1t", "已投 3.6t", "已投 0.4t", "已投 1.8t", "已投 0.3t"},
        {"剩余 2.2t", "剩余 1.5t", "剩余 0.9t", "剩余 2.9t", "剩余 0.3t", "剩余 2.7t", "剩余 0.4t"}
    }));
    setMainPageOperStageData(NavTreeIndex::Main_4, makeOperStageData({
        {"石灰 4.8t", "石灰石 3.2t", "高镁灰 1.8t", "烧结矿 5.8t", "萤石 0.6t", "废钢 4.1t", "合金 0.6t"},
        {"已投 2.1t", "已投 1.4t", "已投 0.9t", "已投 3.2t", "已投 0.3t", "已投 1.4t", "已投 0.2t"},
        {"剩余 2.7t", "剩余 1.8t", "剩余 0.9t", "剩余 2.6t", "剩余 0.3t", "剩余 2.7t", "剩余 0.4t"}
    }));
    setMainPageOperStageData(NavTreeIndex::Main_5, makeOperStageData({
        {"石灰 5.5t", "石灰石 3.4t", "高镁灰 2.4t", "烧结矿 6.8t", "萤石 0.8t", "废钢 4.6t", "合金 0.8t"},
        {"已投 2.8t", "已投 1.8t", "已投 1.3t", "已投 3.5t", "已投 0.4t", "已投 1.9t", "已投 0.3t"},
        {"剩余 2.7t", "剩余 1.6t", "剩余 1.1t", "剩余 3.3t", "剩余 0.4t", "剩余 2.7t", "剩余 0.5t"}
    }));
    setMainPageOperStageData(NavTreeIndex::Main_6, makeOperStageData({
        {"石灰 4.9t", "石灰石 3.1t", "高镁灰 2.1t", "烧结矿 6.1t", "萤石 0.7t", "废钢 4.3t", "合金 0.6t"},
        {"已投 2.4t", "已投 1.6t", "已投 1.0t", "已投 3.0t", "已投 0.3t", "已投 1.5t", "已投 0.3t"},
        {"剩余 2.5t", "剩余 1.5t", "剩余 1.1t", "剩余 3.1t", "剩余 0.4t", "剩余 2.8t", "剩余 0.3t"}
    }));

    setMainPageOperStageItem(NavTreeIndex::Main_1, 1, 0, "已投 2.8t");

    setMainPageOperTotalData(NavTreeIndex::Main_1, makeOperTotalData({
        {"计划投入量", "5.0", "3.0", "2.0", "6.0", "0.5", "4.0", "0.6"},
        {"已投入量", "2.8", "1.6", "1.1", "3.2", "0.2", "1.7", "0.3"},
        {"剩余投入量", "2.2", "1.4", "0.9", "2.8", "0.3", "2.3", "0.3"}
    }));
    setMainPageOperTotalData(NavTreeIndex::Main_2, makeOperTotalData({
        {"计划投入量", "4.5", "2.8", "2.2", "5.5", "0.6", "4.2", "0.5"},
        {"已投入量", "2.1", "1.4", "1.2", "3.0", "0.3", "1.6", "0.2"},
        {"剩余投入量", "2.4", "1.4", "1.0", "2.5", "0.3", "2.6", "0.3"}
    }));
    setMainPageOperTotalData(NavTreeIndex::Main_3, makeOperTotalData({
        {"计划投入量", "5.2", "3.5", "2.0", "6.5", "0.7", "4.5", "0.7"},
        {"已投入量", "3.1", "2.1", "1.1", "3.7", "0.4", "1.9", "0.3"},
        {"剩余投入量", "2.1", "1.4", "0.9", "2.8", "0.3", "2.6", "0.4"}
    }));
    setMainPageOperTotalData(NavTreeIndex::Main_4, makeOperTotalData({
        {"计划投入量", "4.8", "3.2", "1.8", "5.8", "0.6", "4.1", "0.6"},
        {"已投入量", "2.2", "1.5", "0.9", "3.1", "0.3", "1.4", "0.2"},
        {"剩余投入量", "2.6", "1.7", "0.9", "2.7", "0.3", "2.7", "0.4"}
    }));
    setMainPageOperTotalData(NavTreeIndex::Main_5, makeOperTotalData({
        {"计划投入量", "5.5", "3.4", "2.4", "6.8", "0.8", "4.6", "0.8"},
        {"已投入量", "2.9", "1.9", "1.3", "3.6", "0.4", "2.0", "0.3"},
        {"剩余投入量", "2.6", "1.5", "1.1", "3.2", "0.4", "2.6", "0.5"}
    }));
    setMainPageOperTotalData(NavTreeIndex::Main_6, makeOperTotalData({
        {"计划投入量", "4.9", "3.1", "2.1", "6.1", "0.7", "4.3", "0.6"},
        {"已投入量", "2.5", "1.7", "1.0", "3.0", "0.3", "1.5", "0.3"},
        {"剩余投入量", "2.4", "1.4", "1.1", "3.1", "0.4", "2.8", "0.3"}
    }));

    setMainPageOperTotalItem(NavTreeIndex::Main_1, 1, 1, "1.7");

    setMainPageProcessData(NavTreeIndex::Main_1, makeProcessData(
        ProcessStage_BlowingStart, "05'31\"", {true, true, true, true, false, false, false, false, false}));
    setMainPageProcessData(NavTreeIndex::Main_2, makeProcessData(
        ProcessStage_PourMoltenIron, "04'20\"", {true, true, true, false, false, false, false, false, false}));
    setMainPageProcessData(NavTreeIndex::Main_3, makeProcessData(
        ProcessStage_BlowingEnd, "06'05\"", {true, true, true, true, true, false, false, false, false}));
    setMainPageProcessData(NavTreeIndex::Main_4, makeProcessData(
        ProcessStage_TappingSteel, "07'12\"", {true, true, true, true, true, true, false, false, false}));
    setMainPageProcessData(NavTreeIndex::Main_5, makeProcessData(
        ProcessStage_SlagSplashing, "08'00\"", {true, true, true, true, true, true, true, false, false}));
    setMainPageProcessData(NavTreeIndex::Main_6, makeProcessData(
        ProcessStage_SlagRemoval, "08'45\"", {true, true, true, true, true, true, true, true, false}));
    setMainPageVideoData(NavTreeIndex::Main_1, MainPageVideoData{"预喷", "加入石灰301kg,降枪10cm", true});
    setMainPageVideoData(NavTreeIndex::Main_2, MainPageVideoData{"加料", "注意高温，保持喷枪距离", false});
    setMainPageVideoData(NavTreeIndex::Main_3, MainPageVideoData{"吹炼", "观察火焰颜色，调整氧流", false});
    setMainPageVideoData(NavTreeIndex::Main_4, MainPageVideoData{"取样", "请准备取样工具", false});
    setMainPageVideoData(NavTreeIndex::Main_5, MainPageVideoData{"出钢准备", "检查出钢口是否畅通", false});
    setMainPageVideoData(NavTreeIndex::Main_6, MainPageVideoData{"出钢", "注意安全，防止溅渣", true});
    setMainPageChartTableItem(NavTreeIndex::Main_1, 0, 3, "1355");

    const char* configJson = R"({
        "working_condition": [
            { "index": 10, "moltenIron": { "mn": 0.45, "p": 0.12, "s": 0.03, "ti": 0.01, "other": 0.0 },
              "target": { "c": 0.18, "si": 0.02, "mn": 0.60, "p": 0.015, "s": 0.01, "t": 1650 },
              "scrapSteel": { "c": 0.20, "si": 0.10, "mn": 0.30, "oxidation": 0.05 },
              "chuteFlow": { "normal": 2.5, "retain": 1.2, "total": 3.0, "more": 0.5, "less": 0.2, "none": 0.0 } },
            { "index": 20, "moltenIron": { "mn": 0.47, "p": 0.11, "s": 0.02, "ti": 0.01, "other": 0.0 },
              "target": { "c": 0.19, "si": 0.03, "mn": 0.58, "p": 0.016, "s": 0.011, "t": 1645 },
              "scrapSteel": { "c": 0.22, "si": 0.11, "mn": 0.28, "oxidation": 0.04 },
              "chuteFlow": { "normal": 2.6, "retain": 1.1, "total": 3.1, "more": 0.4, "less": 0.3, "none": 0.0 } },
            { "index": 30, "moltenIron": { "mn": 0.46, "p": 0.13, "s": 0.04, "ti": 0.02, "other": 0.0 },
              "target": { "c": 0.17, "si": 0.02, "mn": 0.59, "p": 0.014, "s": 0.012, "t": 1655 },
              "scrapSteel": { "c": 0.21, "si": 0.09, "mn": 0.31, "oxidation": 0.06 },
              "chuteFlow": { "normal": 2.4, "retain": 1.3, "total": 3.2, "more": 0.6, "less": 0.1, "none": 0.0 } },
            { "index": 40, "moltenIron": { "mn": 0.44, "p": 0.10, "s": 0.03, "ti": 0.01, "other": 0.0 },
              "target": { "c": 0.20, "si": 0.03, "mn": 0.57, "p": 0.017, "s": 0.013, "t": 1640 },
              "scrapSteel": { "c": 0.23, "si": 0.12, "mn": 0.29, "oxidation": 0.05 },
              "chuteFlow": { "normal": 2.7, "retain": 1.0, "total": 3.3, "more": 0.5, "less": 0.2, "none": 0.1 } },
            { "index": 50, "moltenIron": { "mn": 0.48, "p": 0.14, "s": 0.02, "ti": 0.02, "other": 0.0 },
              "target": { "c": 0.18, "si": 0.01, "mn": 0.61, "p": 0.016, "s": 0.010, "t": 1660 },
              "scrapSteel": { "c": 0.24, "si": 0.13, "mn": 0.32, "oxidation": 0.04 },
              "chuteFlow": { "normal": 2.8, "retain": 1.4, "total": 3.4, "more": 0.7, "less": 0.3, "none": 0.1 } },
            { "index": 60, "moltenIron": { "mn": 0.43, "p": 0.12, "s": 0.03, "ti": 0.01, "other": 0.0 },
              "target": { "c": 0.19, "si": 0.02, "mn": 0.55, "p": 0.015, "s": 0.012, "t": 1648 },
              "scrapSteel": { "c": 0.22, "si": 0.10, "mn": 0.30, "oxidation": 0.05 },
              "chuteFlow": { "normal": 2.5, "retain": 1.1, "total": 3.1, "more": 0.4, "less": 0.2, "none": 0.0 } }
        ],
        "oxygen_lance": [
            { "index": 11, "lanceDivision": [100, 120, 140, 160, 180, 200],
              "postBlowOxygenUtilization": 0.85,
              "initialOxygenFactor": { "a": 1.2, "b": 0.8 },
              "actualOxygenFlow": 520,
              "sinteredOreGrade": 62.5,
              "cokeBreezeCarbonContent": 0.15,
              "limestoneCO2Content": 0.07,
              "oxygenSupply": { "sinter": 1500, "steel": 300, "coke": 200, "limestone": 180 },
              "adjustMoltenIronCUpperLimit": 0.45,
              "adjustmentRatio": 0.30 },
            { "index": 21, "lanceDivision": [110, 130, 150, 170, 190, 210],
              "postBlowOxygenUtilization": 0.83,
              "initialOxygenFactor": { "a": 1.1, "b": 0.7 },
              "actualOxygenFlow": 510,
              "sinteredOreGrade": 61.0,
              "cokeBreezeCarbonContent": 0.14,
              "limestoneCO2Content": 0.06,
              "oxygenSupply": { "sinter": 1480, "steel": 320, "coke": 190, "limestone": 170 },
              "adjustMoltenIronCUpperLimit": 0.44,
              "adjustmentRatio": 0.28 },
            { "index": 31, "lanceDivision": [105, 125, 145, 165, 185, 205],
              "postBlowOxygenUtilization": 0.82,
              "initialOxygenFactor": { "a": 1.0, "b": 0.75 },
              "actualOxygenFlow": 530,
              "sinteredOreGrade": 63.0,
              "cokeBreezeCarbonContent": 0.16,
              "limestoneCO2Content": 0.08,
              "oxygenSupply": { "sinter": 1510, "steel": 290, "coke": 210, "limestone": 185 },
              "adjustMoltenIronCUpperLimit": 0.46,
              "adjustmentRatio": 0.32 },
            { "index": 41, "lanceDivision": [115, 135, 155, 175, 195, 215],
              "postBlowOxygenUtilization": 0.84,
              "initialOxygenFactor": { "a": 1.05, "b": 0.78 },
              "actualOxygenFlow": 515,
              "sinteredOreGrade": 61.8,
              "cokeBreezeCarbonContent": 0.13,
              "limestoneCO2Content": 0.06,
              "oxygenSupply": { "sinter": 1495, "steel": 310, "coke": 205, "limestone": 175 },
              "adjustMoltenIronCUpperLimit": 0.43,
              "adjustmentRatio": 0.27 },
            { "index": 51, "lanceDivision": [108, 128, 148, 168, 188, 208],
              "postBlowOxygenUtilization": 0.86,
              "initialOxygenFactor": { "a": 1.15, "b": 0.82 },
              "actualOxygenFlow": 540,
              "sinteredOreGrade": 62.8,
              "cokeBreezeCarbonContent": 0.17,
              "limestoneCO2Content": 0.09,
              "oxygenSupply": { "sinter": 1520, "steel": 305, "coke": 215, "limestone": 190 },
              "adjustMoltenIronCUpperLimit": 0.47,
              "adjustmentRatio": 0.33 },
            { "index": 61, "lanceDivision": [112, 132, 152, 172, 192, 212],
              "postBlowOxygenUtilization": 0.81,
              "initialOxygenFactor": { "a": 1.08, "b": 0.79 },
              "actualOxygenFlow": 505,
              "sinteredOreGrade": 61.2,
              "cokeBreezeCarbonContent": 0.14,
              "limestoneCO2Content": 0.07,
              "oxygenSupply": { "sinter": 1470, "steel": 295, "coke": 195, "limestone": 165 },
              "adjustMoltenIronCUpperLimit": 0.42,
              "adjustmentRatio": 0.26 }
        ],
        "material": [
            { "index": 12, "feedingMode": { "mode": 1, "csjk": 12.5, "gsjk": 20.3 } },
            { "index": 22, "feedingMode": { "mode": 2, "csjk": 11.8, "gsjk": 19.6 } },
            { "index": 32, "feedingMode": { "mode": 1, "csjk": 12.1, "gsjk": 20.0 } },
            { "index": 42, "feedingMode": { "mode": 3, "csjk": 13.0, "gsjk": 21.2 } },
            { "index": 52, "feedingMode": { "mode": 2, "csjk": 11.5, "gsjk": 19.2 } },
            { "index": 62, "feedingMode": { "mode": 1, "csjk": 12.7, "gsjk": 20.5 } }
        ],
        "main_working_condition": [
            { "index": 11,
              "items": [
                  { "name": "钢种", "value": "Q235B" },
                  { "name": "执行标准", "value": "GB/T 700" },
                  { "name": "铁水重量", "value": "215" },
                  { "name": "废钢重量", "value": "25" }
              ]
            },
            { "index": 21,
              "items": [
                  { "name": "钢种", "value": "Q345" },
                  { "name": "执行标准", "value": "GB/T 1591" },
                  { "name": "铁水重量", "value": "218" },
                  { "name": "废钢重量", "value": "28" }
              ]
            },
            { "index": 31,
              "items": [
                  { "name": "钢种", "value": "Q355" },
                  { "name": "执行标准", "value": "GB/T 3274" },
                  { "name": "铁水重量", "value": "210" },
                  { "name": "废钢重量", "value": "30" }
              ]
            },
            { "index": 41,
              "items": [
                  { "name": "钢种", "value": "Q390" },
                  { "name": "执行标准", "value": "GB/T 1591" },
                  { "name": "铁水重量", "value": "212" },
                  { "name": "废钢重量", "value": "27" }
              ]
            },
            { "index": 51,
              "items": [
                  { "name": "钢种", "value": "Q420" },
                  { "name": "执行标准", "value": "GB/T 1591" },
                  { "name": "铁水重量", "value": "220" },
                  { "name": "废钢重量", "value": "26" }
              ]
            },
            { "index": 61,
              "items": [
                  { "name": "钢种", "value": "Q460" },
                  { "name": "执行标准", "value": "GB/T 1591" },
                  { "name": "铁水重量", "value": "225" },
                  { "name": "废钢重量", "value": "24" }
              ]
            }
        ],
        "main_material": [
            { "index": 11,
              "items": [
                  { "name": "1#石灰石", "value": "32.5" },
                  { "name": "3#高镁灰", "value": "18.2" },
                  { "name": "4#生", "value": "12.0" },
                  { "name": "5#生白", "value": "9.8" },
                  { "name": "6#石灰", "value": "20.3" }
              ]
            },
            { "index": 21,
              "items": [
                  { "name": "1#石灰石", "value": "31.8" },
                  { "name": "3#高镁灰", "value": "17.5" },
                  { "name": "4#生", "value": "11.2" },
                  { "name": "5#生白", "value": "10.1" },
                  { "name": "6#石灰", "value": "19.6" }
              ]
            },
            { "index": 31,
              "items": [
                  { "name": "1#石灰石", "value": "33.1" },
                  { "name": "3#高镁灰", "value": "18.8" },
                  { "name": "4#生", "value": "12.4" },
                  { "name": "5#生白", "value": "9.2" },
                  { "name": "6#石灰", "value": "21.0" }
              ]
            },
            { "index": 41,
              "items": [
                  { "name": "1#石灰石", "value": "30.9" },
                  { "name": "3#高镁灰", "value": "17.9" },
                  { "name": "4#生", "value": "11.8" },
                  { "name": "5#生白", "value": "9.5" },
                  { "name": "6#石灰", "value": "20.1" }
              ]
            },
            { "index": 51,
              "items": [
                  { "name": "1#石灰石", "value": "32.0" },
                  { "name": "3#高镁灰", "value": "19.0" },
                  { "name": "4#生", "value": "12.6" },
                  { "name": "5#生白", "value": "9.9" },
                  { "name": "6#石灰", "value": "20.7" }
              ]
            },
            { "index": 61,
              "items": [
                  { "name": "1#石灰石", "value": "33.4" },
                  { "name": "3#高镁灰", "value": "18.6" },
                  { "name": "4#生", "value": "12.9" },
                  { "name": "5#生白", "value": "10.4" },
                  { "name": "6#石灰", "value": "21.3" }
              ]
            }
        ],
        "main_oxygen_lance": [
            { "index": 11,
              "oxygenFlow": 521.0,
              "lanceHeight": 6.5,
              "readingBlow": 18.3,
              "accumulatedBlow": 246.7,
              "converterAngle": 8.2,
              "oxygenPressure": 0.85
            },
            { "index": 21,
              "oxygenFlow": 515.0,
              "lanceHeight": 6.8,
              "readingBlow": 17.9,
              "accumulatedBlow": 238.4,
              "converterAngle": 7.9,
              "oxygenPressure": 0.83
            },
            { "index": 31,
              "oxygenFlow": 528.5,
              "lanceHeight": 6.3,
              "readingBlow": 18.7,
              "accumulatedBlow": 252.1,
              "converterAngle": 8.5,
              "oxygenPressure": 0.87
            },
            { "index": 41,
              "oxygenFlow": 517.2,
              "lanceHeight": 6.6,
              "readingBlow": 18.1,
              "accumulatedBlow": 244.9,
              "converterAngle": 8.0,
              "oxygenPressure": 0.84
            },
            { "index": 51,
              "oxygenFlow": 523.4,
              "lanceHeight": 6.4,
              "readingBlow": 18.5,
              "accumulatedBlow": 249.3,
              "converterAngle": 8.3,
              "oxygenPressure": 0.86
            },
            { "index": 61,
              "oxygenFlow": 530.1,
              "lanceHeight": 6.7,
              "readingBlow": 19.0,
              "accumulatedBlow": 255.6,
              "converterAngle": 8.6,
              "oxygenPressure": 0.88
            }
        ],
        "main_blowing": [
            { "index": 11,
              "currentTime": "05'31\"",
              "remainingTime": "16'10\"",
              "temperature": "1581℃",
              "carbonContent": "0.045%",
              "operatingMode": "单渣"
            },
            { "index": 21,
              "currentTime": "04'50\"",
              "remainingTime": "15'40\"",
              "temperature": "1570℃",
              "carbonContent": "0.040%",
              "operatingMode": "双渣"
            },
            { "index": 31,
              "currentTime": "05'05\"",
              "remainingTime": "16'20\"",
              "temperature": "1585℃",
              "carbonContent": "0.042%",
              "operatingMode": "单渣"
            },
            { "index": 41,
              "currentTime": "05'20\"",
              "remainingTime": "15'55\"",
              "temperature": "1578℃",
              "carbonContent": "0.043%",
              "operatingMode": "双渣"
            },
            { "index": 51,
              "currentTime": "04'45\"",
              "remainingTime": "16'05\"",
              "temperature": "1588℃",
              "carbonContent": "0.041%",
              "operatingMode": "单渣"
            },
            { "index": 61,
              "currentTime": "05'10\"",
              "remainingTime": "16'30\"",
              "temperature": "1592℃",
              "carbonContent": "0.039%",
              "operatingMode": "双渣"
            }
        ]
    })";
    
     // 设置VideoWidget按钮显示模式
     int result1 = setVideoWidgetButtonDisplayMode(NavTreeIndex::Main_1, 1);
     if (result1 == 0) {
         std::cout << "  [OK] Set button display mode for Main_1 to ShowNormalOnly (only normal button visible)" << std::endl;
     } else {
         std::cerr << "  [FAIL] Failed to set button display mode for Main_1" << std::endl;
     }

     // 设置炉子1的铁水数据
    ConfigWorkingConditionData::MoltenIronComposition moltenIron1;
    moltenIron1.Mn = 0.9;
    moltenIron1.P = 0.15;
    moltenIron1.S = 0.025;
    moltenIron1.Ti = 0.015;
    moltenIron1.other = 0.0555;
    
     int result2 = setSmeltingConfigMoltenIronData(NavTreeIndex::Config_1, moltenIron1);
     if (result2 == 0) {
         std::cout << "  [OK] Set molten iron data for Config_1 successfully" << std::endl;
         std::cout << "        Mn=" << moltenIron1.Mn << ", P=" << moltenIron1.P 
                   << ", S=" << moltenIron1.S << ", Ti=" << moltenIron1.Ti 
                   << ", other=" << moltenIron1.other << std::endl;
     } else {
         std::cerr << "  [FAIL] Failed to set molten iron data for Config_1" << std::endl;
     }

     // 设置工况项
     setMainPageWorkingConditionItem(NavTreeIndex::Main_1, 0, "钢种", "Q235B");
     std::cout << "  [OK] Set working condition item 0: 钢种 = Q235B" << std::endl;
     std::cout << "       (This will trigger MainPageWorkingConditionCallback)" << std::endl;
     setMainPageWorkingConditionItem(NavTreeIndex::Main_1, 1, "执行标准", "GB/T 700");
     std::cout << "  [OK] Set working condition item 1: 执行标准 = GB/T 700" << std::endl;
     setMainPageWorkingConditionItem(NavTreeIndex::Main_1, 2, "铁水重量", "215");
     std::cout << "  [OK] Set working condition item 2: 铁水重量 = 215" << std::endl;
     
     // 设置料仓项
     setMainPageMaterialItem(NavTreeIndex::Main_1, 0, "1#石灰石", "32.5");
     std::cout << "  [OK] Set material item 0: 1#石灰石 = 32.5" << std::endl;
     std::cout << "       (This will trigger MainPageMaterialCallback)" << std::endl;
     setMainPageMaterialItem(NavTreeIndex::Main_1, 1, "3#高镁灰", "18.2");
     std::cout << "  [OK] Set material item 1: 3#高镁灰 = 18.2" << std::endl;
     setMainPageMaterialItem(NavTreeIndex::Main_1, 2, "4#生", "12.0");
     std::cout << "  [OK] Set material item 2: 4#生 = 12.0" << std::endl;
     
     // 设置氧枪及转炉字段
     setMainPageOxygenLanceField(NavTreeIndex::Main_1, "氧气流量", 520.0);
     std::cout << "  [OK] Set oxygen lance field: 氧气流量 = 520.0" << std::endl;
     std::cout << "       (This will trigger MainPageOxygenLanceCallback)" << std::endl;
     setMainPageOxygenLanceField(NavTreeIndex::Main_1, "氧枪高度", 150.0);
     std::cout << "  [OK] Set oxygen lance field: 氧枪高度 = 150.0" << std::endl;
     setMainPageOxygenLanceField(NavTreeIndex::Main_1, "转炉角度", 45.0);
     std::cout << "  [OK] Set oxygen lance field: 转炉角度 = 45.0" << std::endl;
     // 设置吹炼及提示字段
     setMainPageBlowingField(NavTreeIndex::Main_1, "当前吹炼时间", "05'31\"");
     std::cout << "  [OK] Set blowing field: 当前吹炼时间 = 05'31\"" << std::endl;
     std::cout << "       (This will trigger MainPageBlowingCallback)" << std::endl;
     setMainPageBlowingField(NavTreeIndex::Main_1, "当前温度", "1650");
     std::cout << "  [OK] Set blowing field: 当前温度 = 1650" << std::endl;
     setMainPageBlowingField(NavTreeIndex::Main_1, "操作模式", "自动");
     std::cout << "  [OK] Set blowing field: 操作模式 = 自动" << std::endl;
     
     std::cout << "\nNote: Each item/field change will trigger the corresponding callback function" << std::endl;
     std::cout << "      The callback functions will output the updated data to the console" << std::endl;
 
     std::cout << "Starting UI (initialization and display)..." << std::endl;
     std::cout << "The UI will run until the window is closed." << std::endl;
 
     int result = startUI(argc, argv, "");
     if (result != 0) {
         std::cerr << "Failed to start UI" << std::endl;
         return 1;
     }
     
     // 示例：设置主界面工况和料仓单个项（会触发回调）
     std::cout << "\n=== Setting MainPage Working Condition and Material Items ===" << std::endl;
    
    // Unregister callback functions (optional, but recommended before program exit)
    std::cout << "\nUnregistering callback functions..." << std::endl;
    if (workingConditionCallbackId > 0) {
        if (unregisterCallback(workingConditionCallbackId) == 0) {
            std::cout << "  [OK] Working Condition callback unregistered successfully" << std::endl;
        } else {
            std::cerr << "  [FAIL] Failed to unregister Working Condition callback" << std::endl;
        }
    }
    if (oxygenLanceCallbackId > 0) {
        if (unregisterCallback(oxygenLanceCallbackId) == 0) {
            std::cout << "  [OK] Oxygen Lance callback unregistered successfully" << std::endl;
        } else {
            std::cerr << "  [FAIL] Failed to unregister Oxygen Lance callback" << std::endl;
        }
    }
    if (materialCallbackId > 0) {
        if (unregisterCallback(materialCallbackId) == 0) {
            std::cout << "  [OK] Material callback unregistered successfully" << std::endl;
        } else {
            std::cerr << "  [FAIL] Failed to unregister Material callback" << std::endl;
        }
    }
    if (loginCallbackId > 0) {
        if (unregisterCallback(loginCallbackId) == 0) {
            std::cout << "  [OK] Login callback unregistered successfully" << std::endl;
        } else {
            std::cerr << "  [FAIL] Failed to unregister Login callback" << std::endl;
        }
    }
    if (mainPageWorkingCallbackId > 0) {
        if (unregisterCallback(mainPageWorkingCallbackId) == 0) {
            std::cout << "  [OK] MainPage Working Condition callback unregistered successfully" << std::endl;
        } else {
            std::cerr << "  [FAIL] Failed to unregister MainPage Working Condition callback" << std::endl;
        }
    }
    if (mainPageMaterialCallbackId > 0) {
        if (unregisterCallback(mainPageMaterialCallbackId) == 0) {
            std::cout << "  [OK] MainPage Material callback unregistered successfully" << std::endl;
        } else {
            std::cerr << "  [FAIL] Failed to unregister MainPage Material callback" << std::endl;
        }
    }
    if (mainPageOxygenCallbackId > 0) {
        if (unregisterCallback(mainPageOxygenCallbackId) == 0) {
            std::cout << "  [OK] MainPage Oxygen Lance callback unregistered successfully" << std::endl;
        } else {
            std::cerr << "  [FAIL] Failed to unregister MainPage Oxygen Lance callback" << std::endl;
        }
    }
    if (mainPageBlowingCallbackId > 0) {
        if (unregisterCallback(mainPageBlowingCallbackId) == 0) {
            std::cout << "  [OK] MainPage Blowing callback unregistered successfully" << std::endl;
        } else {
            std::cerr << "  [FAIL] Failed to unregister MainPage Blowing callback" << std::endl;
        }
    }
    if (mainPageOperStageCallbackId > 0) {
        if (unregisterCallback(mainPageOperStageCallbackId) == 0) {
            std::cout << "  [OK] MainPage OperStage callback unregistered successfully" << std::endl;
        } else {
            std::cerr << "  [FAIL] Failed to unregister MainPage OperStage callback" << std::endl;
        }
    }
    if (mainPageOperTotalCallbackId > 0) {
        if (unregisterCallback(mainPageOperTotalCallbackId) == 0) {
            std::cout << "  [OK] MainPage OperTotal callback unregistered successfully" << std::endl;
        } else {
            std::cerr << "  [FAIL] Failed to unregister MainPage OperTotal callback" << std::endl;
        }
    }
    if (mainPageProcessCallbackId > 0) {
        if (unregisterCallback(mainPageProcessCallbackId) == 0) {
            std::cout << "  [OK] MainPage Process callback unregistered successfully" << std::endl;
        } else {
            std::cerr << "  [FAIL] Failed to unregister MainPage Process callback" << std::endl;
        }
    }
    if (mainPageVideoCallbackId > 0) {
        if (unregisterCallback(mainPageVideoCallbackId) == 0) {
            std::cout << "  [OK] MainPage Video callback unregistered successfully" << std::endl;
        } else {
            std::cerr << "  [FAIL] Failed to unregister MainPage Video callback" << std::endl;
        }
    }
    if (mainPageVideoWindowHandleCallbackId > 0) {
        if (unregisterCallback(mainPageVideoWindowHandleCallbackId) == 0) {
            std::cout << "  [OK] MainPage Video window handle callback unregistered successfully" << std::endl;
        } else {
            std::cerr << "  [FAIL] Failed to unregister MainPage Video window handle callback" << std::endl;
        }
    }
    if (shutdownCallbackId > 0) {
        if (unregisterCallback(shutdownCallbackId) == 0) {
            std::cout << "  [OK] Application shutdown callback unregistered successfully" << std::endl;
        } else {
            std::cerr << "  [FAIL] Failed to unregister Application shutdown callback" << std::endl;
        }
    }
    if (debugButtonCallbackId > 0) {
        if (unregisterCallback(debugButtonCallbackId) == 0) {
            std::cout << "  [OK] DebugWidget button callback unregistered successfully" << std::endl;
        } else {
            std::cerr << "  [FAIL] Failed to unregister DebugWidget button callback" << std::endl;
        }
    }
    if (mainPageChartCallbackId > 0) {
        if (unregisterCallback(mainPageChartCallbackId) == 0) {
            std::cout << "  [OK] MainPage Chart callback unregistered successfully" << std::endl;
        } else {
            std::cerr << "  [FAIL] Failed to unregister MainPage Chart callback" << std::endl;
        }
    }
    
    if (result == 0) {
        std::cout << "\nUI closed normally" << std::endl;
    } else {
        std::cerr << "\nUI exited with error code: " << result << std::endl;
    }
    
    std::cout << "Program ended" << std::endl;
    return 0;
}
